package com.kcloud.commons.tools.codebuilder.toolkit;

import com.kcloud.commons.entity.control.AttributeGroup;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 数据表对象
 * @author songhuiqing
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DBTable {

    private String name;
    private String remark;
    private List<DBTableColumn> columns;

    /**
     * 获取属性集类型
     * @return
     */
    public String getTableGroupType() {
        String[] tableRemarkSplit = getTableRemarkSplit();
        if(tableRemarkSplit.length > 1) {
            return tableRemarkSplit[0];
        }
        return AttributeGroup.GROUP_TYPE_CHILD;
    }

    /**
     * 获取表名描述
     * @return
     */
    public String getTableDesc() {
        String[] tableRemarkSplit = getTableRemarkSplit();
        if(tableRemarkSplit.length > 1) {
            return tableRemarkSplit[1];
        }
        return tableRemarkSplit[0];
    }

    public String[] getTableRemarkSplit() {
        if(remark != null) {
            return remark.split("-");
        }
        return new String[]{""};
    }

}
